﻿using System;
using System.Diagnostics;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.QueryParsers;
using Lucene.Net.Search;

namespace LuceneSearch.Searcher
{
    class Program
    {
        static void Main(string[] args)
        {
            var indexDir = args[0];
            var queryText = args[1];

            var indexSearcher = new IndexSearcher(indexDir);
            var queryParser = new QueryParser("contents", new StandardAnalyzer());
            var query = queryParser.Parse(queryText);

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            var hits = indexSearcher.Search(query);

            Console.WriteLine("Found {0} documents(s) in {1} milliseconds:", hits.Length(), stopwatch.ElapsedMilliseconds);

            for (var i = 0; i < hits.Length(); i++)
            {
                var doc = hits.Doc(i);

                Console.WriteLine(doc.Get("path"));
            }
        }
    }
}
